package com.kehao.leetcode.jzoffer;

import org.junit.Test;

/**
 * @author Kehao.Chen
 * @version 1.0
 * @date 2022/7/5 13:47
 */
public class JZSolution045 {

    private static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(int val) { this.val = val; }
        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    private int result;
    private int maxLevel;
    private void dfs(TreeNode node,int level){
        if(node==null) return;
        if(level>maxLevel){
            maxLevel = level;
            result = node.val;
        }
        dfs(node.left,level+1);
        dfs(node.right,level+1);
    }

    public int findBottomLeftValue(TreeNode root) {
        result = root.val;
        maxLevel = 0;
        dfs(root,0);
        return result;
    }

    @Test
    public void test01(){

    }
}
